package amazing.core.logging;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Date;
public final class Logger {
	public static void log(String str)
	{
		log(LogLevel.Normal, str, true, true);
	}
	public static void log(LogLevel level, String str)
	{
		log(level, str, true, true);
	}
	public static void log(String str, boolean attachPrefix)
	{
		log(LogLevel.Normal, str, attachPrefix, true);
	}
	public static void log(LogLevel level, Loggable logger)
	{
		log(level, logger.log(level), false, false);
	}
	public static void log(LogLevel level, String str, boolean attachPrefix)
	{
		log(level, str, attachPrefix, true);
	}
	public static void log(LogLevel level, String str, boolean attachPrefix, boolean attachPostfix)
	{
		String strout = "";
		if (str == null)
			str = "null";
		if (attachPrefix)
			strout = "[" + level.toString() + "]@(" + new Date().toString() + ") :: ";
		strout += str.replaceAll("[\r\n]+", "\r\n\t");
		if (attachPostfix)
		{
			final StackTraceElement[] ste =  new Throwable().getStackTrace();
			int pos = ste.length - 2;
			while (pos > -1 && ste[pos].getClassName().equals("amazing.core.logging.Logger"))
				pos--;
			if (pos < 0)
				pos = ste.length - 1;
			strout += " {" + ste[pos].getClassName() + "." + ste[pos].getMethodName() + 
					"[" + ste[pos].getFileName() + ":" + ste[pos].getLineNumber() + "]}";
		}
		
		System.out.println(strout);
	}
}
